package com.venutech.gongan.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.PageUtils;
import com.venutech.gongan.dao.YjydMapper;
import com.venutech.gongan.entity.Yjyd;
import com.venutech.gongan.model.ResultFormat;
import com.venutech.gongan.service.YjydService;
import com.venutech.gongan.util.ResultUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class YjydServiceImpl implements YjydService {
    @Resource
    private YjydMapper yjydMapper;


    @Override
    public ResultFormat insert(Yjyd yjyd) {
        Integer insert = yjydMapper.insert(yjyd);
        if (insert > 0) {
            return ResultUtil.success();
        }else {
            return ResultUtil.error(100,"添加失败");
        }
    }

    @Override
    public int deleteById(Integer yj_id) {
        return yjydMapper.deleteById(yj_id);
    }

    @Override
    public Yjyd getById(Integer yj_id) {
        return yjydMapper.getById(yj_id);
    }

    @Override
    public int updateYjyd(Yjyd yjyd) {
        return yjydMapper.updateYjyd(yjyd);
    }

    @Override
    public Page<Yjyd> getInfo(Integer pageNo, Integer pageSize, String begintime, String endtime, String badw, Integer yj_id) {
        Page<Yjyd> page = new Page<>(pageNo,pageSize);
        PageUtils.startPage();
        List<Yjyd> list = yjydMapper.getInfo(begintime,endtime,badw,page,yj_id);
        page.setTotal(new PageInfo<>(list).getTotal());
        return page.setRecords(list);
    }

    @Override
    public Page<Yjyd> getInfo2(Integer pageNo, Integer pageSize, String begintime, String endtime,
                                String badw) {
        Page<Yjyd> page = new Page<>(pageNo,pageSize);
        PageUtils.startPage();
        List<Yjyd> list = yjydMapper.getInfo2(begintime,endtime,badw,page);
        page.setTotal(new PageInfo<>(list).getTotal());
        return page.setRecords(list);
    }
}
